package com.tadpole.music.view.activity.login;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tadpole.music.R;
import com.tadpole.music.utils.Mutils;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.utils.ToastUtils;
import com.tadpole.music.view.activity.base.BaseActivity;

/**
 * 选择身份
 * Created By 孙岩
 * on 2020/9/10
 */
public class SelectIdentityActivity extends BaseActivity {
    //回退键
    private View view_back_icon;
    //标题
    private TextView actionbar_title;
    //我是老师
    private RelativeLayout rlTeacher;
    //我是学生
    private RelativeLayout rlStudent;
    //确定
    private TextView tvSubmit;
    //状态 1表示学生 2 表示老师
    private int flag = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_identity);
        initViews();
        initListeners();
    }

    //初始化控件
    private void initViews(){
        view_back_icon = findViewById(R.id.view_back_icon);
        actionbar_title = findViewById(R.id.actionbar_title);
        actionbar_title.setText("身份选择");
        rlTeacher = findViewById(R.id.rlTeacher);
        rlStudent = findViewById(R.id.rlStudent);
        tvSubmit = findViewById(R.id.tvSubmit);
    }

    //初始化监听器
    private void initListeners(){
        view_back_icon.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                SelectIdentityActivity.this.finish();
            }
        });

        //我是老师
        rlTeacher.setOnClickListener(new NoDoubleClickListener() {
            @SuppressLint("UseCompatLoadingForDrawables")
            @Override
            protected void onNoDoubleClick(View v) {
                rlTeacher.setBackground(getResources().getDrawable(R.drawable.selector_identity));
                rlStudent.setBackground(getResources().getDrawable(R.drawable.bg_white));
                flag = 2;
            }
        });

        //我是学生
        rlStudent.setOnClickListener(new NoDoubleClickListener() {
            @SuppressLint("UseCompatLoadingForDrawables")
            @Override
            protected void onNoDoubleClick(View v) {
                rlTeacher.setBackground(getResources().getDrawable(R.drawable.bg_white));
                rlStudent.setBackground(getResources().getDrawable(R.drawable.selector_identity));
                flag = 1;
            }
        });

        //确定
        tvSubmit.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if(Mutils.isNetworkAvailable()){
                   if(flag==0){
                       ToastUtils.show("请选择身份");
                   }else{
                       Intent intent = new Intent(SelectIdentityActivity.this,LoginRegisterActivity.class);
                       intent.putExtra("role",flag);
                       startActivity(intent);
                       SelectIdentityActivity.this.finish();
                   }
                }else{
                    ToastUtils.show("请检查您的网络设置");
                }
            }
        });
    }
}
